package cpu.footprint.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.widget.Toast;

/**
 * Created by WJP on 2017/3/5.
 */

public class CreateDialogUtil {
    /**
     * 创建加载对话框
     * @param activity
     * @param text
     * @param mHandler
     * @return
     */
    public static Dialog CreateDialog(Activity activity, String text, final Handler mHandler){
        final Dialog  mDialog = DialogUtil.getLoadDialog(activity,text);
        mDialog.setCancelable(true);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mHandler.removeCallbacksAndMessages(null);
                mDialog.dismiss();
            }
        });
        return mDialog;
    }

    /**
     * 弹出toast
     * @param context
     * @param text
     */
    public static void ToastShow(Context context,String text){
        Toast.makeText(context,text,Toast.LENGTH_SHORT).show();
    }
}
